package main

import (
	"fmt"
	"log"
	"syscall"

	"gitee.com/liuyongchina/go-library/config"
	"gitee.com/liuyongchina/init-project/conf"
	"gitee.com/liuyongchina/init-project/models"
	"gitee.com/liuyongchina/init-project/routers"
	"github.com/fvbock/endless"
)

func main() {
	config.TomlPath = "/Users/liuyong/go/src/init-project/toml/toml_dev/"
	serverConfig := conf.NewServer().GetConfig()
	fmt.Println(serverConfig.EndlessConfig.ReadTimeout)
	models.InitDB()
	endless.DefaultReadTimeOut = serverConfig.EndlessConfig.ReadTimeout
	endless.DefaultWriteTimeOut = serverConfig.EndlessConfig.WriteTimeout
	endless.DefaultMaxHeaderBytes = 1 << 20
	endPoint := fmt.Sprintf("0.0.0.0:%d", serverConfig.EndlessConfig.HttpPort)
	server := endless.NewServer(endPoint, routers.InitRouter(serverConfig.GinConfig))
	server.BeforeBegin = func(add string) {
		log.Printf("Actual pid is %d", syscall.Getpid())
	}
	err := server.ListenAndServe()
	if err != nil {
		log.Printf("Server err: %v", err)
	}
}
